<include file="Public/header.html" />
<style>
.font_color{color: #ff5722;}
.layui-tab-content .layui-form-label{width: 180px;}
.layui-tab-content .layui-input-block{margin-left: 180px;}
.delate_img{width: 26px;position: absolute;height: 26px;line-height: 27px;background: rgba(0,0,0,0.7);text-align: center;top: -10px;
    right: -10px;color: #fff;font-size: 24px;cursor: pointer;border-radius: 100%;}
</style>
</head>
<body>
	<div class="x-body">
		<form class="layui-form">
			
			<div class="layui-form-item">
			   	<label class="layui-form-label">图片</label>
			    <button type="button" class="layui-btn" id="upload_img">
					<i class="layui-icon">&#xe67c;</i>上传图片
				</button>
				<div class="layui-input-block">
					<input id="img_val" name="img" type="hidden" value="{$list['img']}" />
					<?php if(!empty($list['img'])){ ?>
					<img id="img" style="width: 200px;height: 200px;" src="{$list['img']}" />
					<?php }else{ ?>
					<img id="img" style="width: 200px;height: 200px;" src="__ROOT__/Public/images/z_add.png" />
					<?php } ?>
				</div>
			</div>
			
			<div class="layui-form-item">
			    <label class="layui-form-label">跳转类型</label>
				<div class="layui-input-inline">
				    <select name="type" >
				    	<option value="1" <if condition="1 eq $list['type']">selected</if> >链接</option>	
				    	<option value="2" <if condition="2 eq $list['type']">selected</if> >弹窗</option>	
				    </select>
				</div>
			</div>
			
			<div class="layui-form-item">
			    <label class="layui-form-label">跳转链接</label>
			    <div class="layui-input-block">
			       	<input type="text" name="url" value="{$list['url']}"  autocomplete="off" class="layui-input">
			    </div>
			</div>
			
			<div class="layui-form-item">
			   	<label class="layui-form-label">弹框二维码</label>
			    <button type="button" class="layui-btn" id="upload_ewm">
					<i class="layui-icon">&#xe67c;</i>上传图片
				</button>
				<div class="layui-input-block">
					<input id="ewm_val" name="ewm" type="hidden" value="{$list['ewm']}" />
					<?php if(!empty($list['ewm'])){ ?>
					<img id="ewm" style="width: 200px;height: 200px;" src="{$list['ewm']}" />
					<?php }else{ ?>
					<img id="ewm" style="width: 200px;height: 200px;" src="__ROOT__/Public/images/z_add.png" />
					<?php } ?>
				</div>
			</div>
			
			
			<input type="hidden" name="id" value="{$id}" />
			<div class="layui-form-item" style="display: none;">
                <label for="L_sign" class="layui-form-label"></label>
               <input type="button" class="layui-btn" id="submitBtn" key="set-mine" lay-filter="save" lay-submit />
           </div>
		</form>
	</div>
	
	<include file="Public/footer.html" />
	<script type="text/javascript" src="__ROOT__/Public/js/tools.js"></script> 
	<script type="text/javascript" src="__ROOT__/Public/js/jquery.min.js"></script> 
	<script>
		layui.use(['form', 'layer','upload'], function() {
			$ = layui.jquery;
			var form = layui.form;
			var layer = layui.layer;
			var upload = layui.upload;
			
	    	//执行实例
			var uploadInst = upload.render({
			    elem: '#upload_img' //绑定元素
			    ,url: "{:U('Home/Web/System/do_upload')}" //上传接口
			    ,done: function(res){
			    	//上传完毕回调
			    	console.log(res);
			    	$('#img').attr('src',res.path);
			    	$('#img_val').val(res.path);
			    }
			    ,error: function(){
			    	//请求异常回调
			    }
			});
			
			var uploadInst = upload.render({
			    elem: '#upload_ewm' //绑定元素
			    ,url: "{:U('Home/Web/System/do_upload')}" //上传接口
			    ,done: function(res){
			    	//上传完毕回调
			    	console.log(res);
			    	$('#ewm').attr('src',res.path);
			    	$('#ewm_val').val(res.path);
			    }
			    ,error: function(){
			    	//请求异常回调
			    }
			});
			
			form.on('submit(save)', function(data){	
				var tjing = parent.layer.msg('提交中...', {icon: 16,shade: 0.3,time: 60*1000}); 
		        var form = document.forms[0];
	  		    var formData = new FormData(form);
				$.ajax({
			        url: "{:U('Home/Web/Banner/do_banner')}",
			        type : "POST",
			        data :formData,
			        dataType:"text",
			        processData : false,         
			        contentType : false,      
			        success:function(data){
			            parent.layer.close(tjing);
		               	if(data == '1'){
		                 	parent.layer.msg('提交成功', {icon: 1,offset: '40%',time:2000,shade: 0.3},function(){ 
					        	parent.location.reload();
						 	})
		               	}else if(data == '2'){
		              	 	parent.layer.msg('提交失败', {icon: 2,offset: '40%',time:2000,shade: 0.3});
		               	}else{
		               		parent.layer.msg(data, {icon: 2,offset: '40%',time:2000,shade: 0.3});
		               	}
			        }
			    });						
	           		
	            return false;
          	});
		});
	
	</script>
</body>
</html>
